<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    /*
    function dog(){
        this.animal = '狗';
        this.voice = '汪汪汪';
        this.speak = function(){
            console.log(this.voice);
        };
        this.eat = function(){
            console.log('eat ....')
        };
    }

    function cat(){
        this.animal = "猫";
        this.voice = "喵～";
        this.speak =function(){
            console.log(this.voice);
        };
        this.eat = function(){
            console.log('eat ....')
        }
    }

    var dog_A =new dog();
    var cat_A =new cat();

    dog_A.speak();
    cat_A.eat();
    */

    /*
    // 实例继承
    animal = {
        speak:function(){
            console.log(this.voice);
        },
        eat:function(){
            console.log('eat ....');
        }
    };*/

    // 构造继承
    function animal(){
        this.speak =function(){
            console.log(this.voice);
        };
        this.eat = function(){
            console.log('eat ....');
        };
    }


    function dog(){
        this.animal = '狗';
        this.voice = '汪汪汪';
    }
    // dog.prototype = animal;   // 实例继承
    dog.prototype = new animal();// 构造继承

    function cat(){
        this.animal = "猫";
        this.voice = "喵～";
    }
    // cat.prototype = animal;
    cat.prototype = new animal();

    var dog_A =new dog();
    var cat_A =new cat();

    dog_A.speak();
    cat_A.eat();






</script>
</html>